package com.tq.framework.beans;

import com.tq.framework.annotation.Component;
import lombok.EqualsAndHashCode;
import lombok.Getter;

import java.lang.reflect.Constructor;

/**
 * Bean定义
 *
 * @author TqCoder
 * @since 2.0.0
 */
@Getter
@EqualsAndHashCode
public class BeanDefinition {

    private final String name;

    private final Constructor<?> constructor;

    public BeanDefinition(Class<?> clazz) {
        Component component = clazz.getDeclaredAnnotation(Component.class);
        this.name = component.value().isBlank() ? clazz.getSimpleName() : component.value();
        try {
            this.constructor = clazz.getDeclaredConstructor();
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        }
    }
}
